//
// Created by 31897 on 2021/10/22.
//
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int Arr[300],Sum[300];
int Min[300][300], Max[300][300];
int main() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> Arr[i];
        Arr[i + n] = Arr[i];
    }

    for (int i = 1; i <= 2 * n; i++) {
        Sum[i] = Sum[i - 1] + Arr[i];
    }

    for (int i = 2 * n-1; i >= 1; i--) {
        for (int j = i + 1; j < i + n; j++) {
            Min[i][j] = INF;
            for (int k = i; k < j; k++) {
                Min[i][j] = min(Min[i][j], Min[i][k] + Min[k + 1][j] + Sum[j] - Sum[i - 1]);
                Max[i][j] = max(Max[i][j], Max[i][k] + Max[k + 1][j] + Sum[j] - Sum[i - 1]);
            }
        }
    }

    int MaxValue = 0, MinValue = INF;
    for (int i = 1; i <= n; i++) {
        MaxValue = max(MaxValue, Max[i][i + n - 1]);
        MinValue = min(MinValue, Min[i][i + n - 1]);
    }

    cout << MinValue << endl << MaxValue << endl;

}